package ch.ethz.fcl.metrobuzz.render.custom;

import java.awt.Color;

import javax.vecmath.Vector3f;

import org.lwjgl.opengl.GL11;

import ch.ethz.fcl.metrobuzz.tools.MBTools;

/**
 * 
 * Contains some wrapper function around the glCalls. gl.glColor3f -> color, etc
 * 
 * @author CSC
 * 
 */
public abstract class RendererBase{

	protected static final int POINTS = GL11.GL_POINTS;
	protected static final int LINE_STRIP = GL11.GL_LINE_STRIP;

	protected void enableFog() {
		GL11.glEnable(GL11.GL_DEPTH_TEST);
		GL11.glEnable(GL11.GL_FOG);
	}

	protected void disableFog() {
		GL11.glDisable(GL11.GL_FOG);
	}

	protected void lineWidth(double d) {
		GL11.glLineWidth((float) d);
	}

	protected void end() {
		GL11.glEnd();

	}

	protected void vertex(Vector3f v) {
		GL11.glVertex3f(v.x, v.y, v.z);
	}

	protected void begin(int mode) {
		GL11.glBegin(mode);
	}

	protected void color(double r, double g, double b) {
		GL11.glColor3f((float) r, (float) g, (float) b);
	}

	protected void color(double r, double g, double b, double a) {
		GL11.glColor4f((float) r, (float) g, (float) b, (float) a);
	}

	protected void pointSize(double d) {
		GL11.glPointSize((float) d);
	}

	protected void enableAdditiveBlend() {
		GL11.glEnable(GL11.GL_BLEND);
		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
	}

	protected void disableDepthTest() {
		GL11.glDisable(GL11.GL_DEPTH_TEST);
	}

	protected void disableBlend() {
		GL11.glDisable(GL11.GL_BLEND);
	}
	
	protected void lineSmooth(){
		GL11.glEnable(GL11.GL_LINE_SMOOTH);
		GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);		
	}

	protected void enableBlend() {
		GL11.glEnable(GL11.GL_BLEND);
		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
	}

	protected void color(Color col, float alpha) {
		float r = MBTools.map(col.getRed(), 0, 255, 0, 1);
		float g = MBTools.map(col.getGreen(), 0, 255, 0, 1);
		float b = MBTools.map(col.getBlue(), 0, 255, 0, 1);
		GL11.glColor4f(r, g, b, alpha);
	}
}
